/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.controlstudent.datos;

import com.controlstudent.entidades.Nota;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Neil
 */
public class NotaDAO {

    private static NotaDAO instance = null;

    private NotaDAO() {
    }

    public static NotaDAO getInstance() {
        if (instance == null) {
            instance = new NotaDAO();
        }
        return instance;
    }

    public ArrayList<Nota> listarnotasxalum(int id) {
        ArrayList<Nota> notas = null;
        Connection cn = null;

        String sql = "select c1,c2,c3,c4, prom from Notas where alumno_id=?";

        try {
            notas = new ArrayList<>();
            cn = ConnectionManager.getConnection();
            PreparedStatement ps = cn.prepareStatement(sql);
            ps.setInt(1, id);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                Nota n = new Nota();
                n.setC1(rs.getInt("c1"));
                n.setC2(rs.getInt("c2"));
                n.setC3(rs.getInt("c3"));
                n.setC4(rs.getInt("c4"));
                n.setProm(rs.getInt("prom"));
                notas.add(n);
            }
        } catch (Exception e) {
        } finally {
            try {
                cn.close();
            } catch (SQLException ex) {
            }
        }
        return notas;
    }

}
